package cn.gz.coolshark.mapper;

import cn.gz.coolshark.pojo.entity.Product;
import cn.gz.coolshark.pojo.vo.ProductAdminVO;
import cn.gz.coolshark.pojo.vo.ProductDetailVO;
import cn.gz.coolshark.pojo.vo.ProductIndexVO;
import cn.gz.coolshark.pojo.vo.ProductTopVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Insert("insert into product values(null,#{title},#{price},#{oldPrice},#{saleCount},#{num},#{categoryId},#{url},#{viewCount},#{created})")
    int insert(Product product);
    @Select("select id,title,price,old_price as oldPrice,num,url from product")
    List<ProductAdminVO> selectForAdmin();
    @Select("select url from product where id=#{id}")
    String selectUrlById(int id);
    @Delete("delete from product where id=#{id}")
    void deleteById(int id);
    @Select("select id,title,sale_count as saleCount from product order by saleCount desc limit 0,6")
    List<ProductTopVO> selectTop();
    @Select("select id,title,price,old_price as oldPrice,sale_count as saleCount,url from product")
    List<ProductIndexVO> selectForIndex();
    @Select("select id,title,price,old_price as oldPrice,sale_count as saleCount,viewCount,url from product where id=#{id}")
    ProductDetailVO selectDetailById(int id);
    @Select("select id,title,price,old_price as oldPrice,sale_count as saleCount,url from product where categoryId=#{id}")
    List<ProductIndexVO> selectByCategoryId(int id);
    @Select("select id,title,price,old_price as oldPrice,sale_count as saleCount,url from product where title like concat('%',#{wd},'%')")
    List<ProductIndexVO> selectByWd(String wd);
}
